package com.cn.wanxi.servlet.pageDataFindAll;

import com.alibaba.fastjson.JSONObject;
import com.cn.wanxi.model.*;
import com.cn.wanxi.service.*;
import com.cn.wanxi.service.impl.*;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/home")
public class HomeServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//          获得公司信息
        ICompanyService companyService=new CompanyServiceImpl();
        CompanyModel companyModel=companyService.findAll();

//          导航循环
        INavigationService navService=new NavigationServiceImpl();
        List<NavigationModel> findNavigation=navService.findAll();
//        req.setAttribute("navService", navService.findAll());

//          循环新闻
        INewsService newsService=new NewsServiceImpl();
        List<NewsModel> newsFind=newsService.newsFindAllsom();
//        req.setAttribute("homeService",newsService.newsFindAllTh(newsModel));


//项目
        IProductService iProductService =new ProductServiceImpl();
        List<ProductModel> productFind=iProductService.productFind();
//        req.setAttribute("iProductService",iProductService.findAll(pageModel));


// 产品
        IProductsService iProductsService =new ProductsServiceImpl();
        List<ProductModel> productsFind=iProductsService.productsFind();
//        req.setAttribute("iProductService",iProductService.findAll(pageModel));

//        req.getRequestDispatcher("/jsp/home.jsp").forward(req, resp);
        JSONObject jsonObject=new JSONObject();
        jsonObject.put("companyModel",companyModel);
        jsonObject.put("findNavigation",findNavigation);
        jsonObject.put("newsFind",newsFind);
        jsonObject.put("productFind",productFind);
        jsonObject.put("productsFind",productsFind);
        resp.getWriter().println(jsonObject);
    }
}


